package com.kay.web;

import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;

import javax.servlet.ServletException;
import java.io.File;

/**
 * @Description:
 * @Author: Kay
 * @CreateDate: 2021/7/26$ 22:00$
 * @UpdateUser: Kay
 * @UpdateDate: 2021/7/26$ 22:00$
 */
public class TomcatWebServer {

    public void initialize(){
        //实例化一个Tomcat
        Tomcat tomcat = new Tomcat();
        tomcat.setPort(9090);
        try {
            tomcat.addWebapp("/", new File("src/main").getAbsolutePath()).setReloadable(false);
            tomcat.start();
            tomcat.getServer().await();
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (LifecycleException e) {
            e.printStackTrace();
        }
    }
}
